package com.yyplatform.frontend.infra.entity;

import java.util.Date;

import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;
import lombok.Getter;
import lombok.Setter;

/**
 * Created on 2024-10-17
 */
@Getter
@Setter
@MappedSuperclass
public class BaseEntity {
    @Id
    @Column(name = "id", columnDefinition = " bigint(20) comment '主键ID'")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;


    @Column(name = "create_by", updatable = false, nullable = false, columnDefinition = " varchar(50) comment '创建人' ")
    private String createBy;

    @Column(name = "create_time", updatable = false, nullable = false, columnDefinition = " datetime comment '创建时间' ")
    private Date createTime;


    @Column(name = "update_by", nullable = false, columnDefinition = " varchar(50) comment '更新人'")
    private String updateBy;

    @Column(name = "update_time", nullable = false, columnDefinition = " datetime comment '更新时间' ")
    private Date updateTime;


    @PrePersist
    protected void onCreate() {
        Date now = new Date();
        createTime = now;
        updateTime = now;

        createBy = "";
        updateBy = "";
    }


    @PreUpdate
    protected void onUpdate() {
        long t = System.currentTimeMillis();
        Date date = new Date(t);
        this.setUpdateTime(date);
    }


}
